package com.qianchang.microfinance.view.hsbindbank;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import android.webkit.JavascriptInterface;

import com.qianchang.microfinance.view.credit.data.ScanFaceActivity;
import com.just.agentweb.AgentWeb;

/**
 * Created by cenxiaozhong on 2017/5/14.
 *  source CODE  https://github.com/Justson/AgentWeb
 */

public class HSBindBankCardAndroidInterface {

    private Handler deliver = new Handler(Looper.getMainLooper());
    private AgentWeb agent;
    private Context context;
    private HSBindBankCardActivity hsBindBankCardActivity;


    public HSBindBankCardAndroidInterface(AgentWeb agent, Context context) {
        this.agent = agent;
        this.context = context;
        this.hsBindBankCardActivity = (HSBindBankCardActivity) context;
    }



    @JavascriptInterface
    public void mSkipBack(final String action, final String result) {


        deliver.post(new Runnable() {
            @Override
            public void run() {
                Log.i("Info", "main Thread:" + Thread.currentThread());
                if(action.equals("bindBankCard") && result.equals("success")){            //绑定银行卡返回页面按钮
                    if(hsBindBankCardActivity.isConfirmlGoing()){   //如果是从认证中心来的 则直接销毁
                        hsBindBankCardActivity.finish();
                    }else {    //不是 则跳转至人脸识别
                        Intent intent = new Intent();
                        intent.setClass(hsBindBankCardActivity,ScanFaceActivity.class);
                        Bundle bundle = new Bundle();
                        bundle.putBoolean("isConfirml",false);
                        intent.putExtras(bundle);
                        hsBindBankCardActivity.startActivity(intent);
                        hsBindBankCardActivity.finish();
                    }
                }else {
                    hsBindBankCardActivity.finish();
                }
            }
        });
        Log.i("Info", "Thread:" + Thread.currentThread());
    }

}
